<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>7ParadigmJips <?php if (isset($_POST['mainPanel'])) echo($_POST['mainPanel']); ?></title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="COMP231 Project">
        <meta name="author" content="Seven Bits, Paradigm Shift, AAH">
        <link href="../css/bootstrap.css" rel="stylesheet">
        <link href="../css/bootstrap-datepicker.css" rel="stylesheet">
        <style type="text/css">
            body {
                padding-top: 60px;
            }
        </style>
    </head>
    <body>


        <!-- begin imports -->
        <?php
        session_start();
        if (!isset($_SESSION['userName'])) {
            header("Location: index.php");
        }
        require_once 'paradigmShift/_paradigmShift.php';
        if (!isset($_SESSION['isManager'])) {
            $managerResults = checkIfManager($_SESSION['userName'], $_SESSION['userPassHash']);
            if ($managerResults['code'] == ErrorCode::successRead) {
                $_SESSION['isManager'] = $managerResults['isManager'];
            } else {
                header("Location: index.php");
            }
        }
        require_once 'checkSessionTimeout.php';
        checkSessionTimeout();
        ?>
        <!-- end imports -->



        <div class="navbar navbar-inverse navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container-fluid">
                    <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="brand" href="#">7ParadigmJips</a>
                    <div class="nav-collapse collapse">
                        <p class="navbar-text pull-right">
                            Logged in as <a href="#" class="navbar-link"><?php echo($_SESSION['userName']); ?></a>
                        </p>
                    </div><!--/.nav-collapse -->
                </div>
            </div>
        </div>


        <div class="container-fluid">
            <div class="row-fluid">
                <nav class="span3">
                    <!-- begin  sidenav -->
                    <?php include_once 'sidebar.php'; ?>
                    <!-- end sidenav -->
                </nav>
                <section class="span9">
                    <!-- begin main body -->
                    <?php
                    //determine which panel is being shown.
                    //default is "upcoming shifts"
                    $mainPanel = "upcoming";
                    if (isset($_POST['mainPanel'])) {
                        //priority is if the user wants to change panel
                        $_SESSION['mainPanel'] = $mainPanel = $_POST['mainPanel'];
                    } elseif (isset($_SESSION['mainPanel'])) {
                        //if not changing, checks to see most recent page
                        $mainPanel = $_SESSION['mainPanel'];
                    }
                    switch ($mainPanel) {
                        case "Add Account":
                            include_once "main_addAccount.php";
                            break;
                        case "Add Shift":
                            include_once "main_addShift.php";
                            break;
                        case "Requests Manager":
                            include_once "main_pendingRequests.php";
                            break;
                        case "Shift Manager":
                            include_once "main_shiftManager.php";
                            break;
                        case "Manager Manager":
                            include_once "main_updateManagers.php";
                            break;
                        case "Employee Manager":
                            include_once "main_empManager.php";
                            break;
                        case "Logout":
                            logout();
                            break;
                        case "Shift Shop":
                            include_once "main_shop.php";
                            break;
                        case "Profile":
                            include_once "main_profile.php";
                            break;
                        case "History":
                            include_once "main_history.php";
                            break;
                        default:
                            include_once "main_upcoming.php";
                            break;
                    }
                    ?>
                    <!-- end main body -->
                </section>
            </div>
        </div>
        <script type="text/javascript" src="../js/jquery.js"></script>
        <script type="text/javascript" src="../js/bootstrap.js"></script>
        <script type="text/javascript" src="../js/bootstrap-datepicker.js"></script>
        <script type="text/javascript">
            $(".datepicker").datepicker({
                format: "yyyy-mm-dd"
            })
        </script>
    </body>
</html>
<?php

function logout() {
    session_destroy();
    header("Location: index.php");
}
?>